package com.vue.vuedemo.Controller;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.vue.vuedemo.pojo.Comment;
import com.vue.vuedemo.pojo.Friend;
import com.vue.vuedemo.pojo.Persons;
import com.vue.vuedemo.service.FriendService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@JsonIgnoreProperties({"hibernateLazyInitializer","handler"})
@CrossOrigin(origins = {"http://localhost:8080"}) //当前网站向另一个网站请求数据就是跨域
@Controller
public class FriendController {

    @Resource
    private FriendService friendService;

    @GetMapping(value = "FriendFindAll")
    public List<Friend> findAll(Integer fUserId){
        List<Friend> list = friendService.findShow(fUserId);
        return list;
    }

    Integer num;

    //添加好友
    @GetMapping(value = "FriendAdd")
    public Integer commentAdd(Integer fFirendID,Integer fUserID ,Friend friend, HttpSession session){

        friend.setFFirendId(fFirendID);
        friend.setFUserId(fUserID);
        try {
            friendService.add(friend);
            num = 1; //成功
        }catch (Exception ex){
            num = 2; //失败
            System.out.print(ex);
        }
        return num;
    }


    //删除好友
    @GetMapping(value = "friendDel")
    public Integer del(Integer fId){
        try {
            friendService.del(fId);
            num = 1; //成功
        }catch (Exception ex){
            num = 2; //失败
        }
        return num;
    }


    //好友申请列表
    @GetMapping(value = "FriendfFirendIdFindAll")
    public List<Friend> fFirendIdfindAll(Integer fFirendID){
        List<Friend> list = friendService.SqShow(fFirendID);
        return list;
    }

    //同意好友申请
    @GetMapping(value = "friendupdatety")
    public Integer friendupdatety(Integer fFirendID,Integer fUserID ,Integer fid,Friend friend){
        friend.setFUserId(fUserID);
        friend.setFFirendId(fFirendID);
        try {
            friendService.FanAdd(friend);
            friendService.updateTy(fid);
            num = 1; //成功
        }catch (Exception ex){
            num = 2; //失败
        }
        return num;
    }

    //不同意好友申请
    @GetMapping(value = "friendupdatebty")
    public Integer friendupdatebty(Integer fid){
        try {
            friendService.updateBty(fid);
            num = 1; //成功
        }catch (Exception ex){
            num = 2; //失败
        }
        return num;
    }

    //被驳回的
    @GetMapping(value = "FriendbhFindAll")
    public List<Friend> FriendbhFindAll(Integer fFirendID){
        List<Friend> list = friendService.BtyShow(fFirendID);
        return list;
    }

    //加好友消息数量
    @GetMapping(value = "countFriendWei")
    public Integer countFriendWei(Integer Jpid){
        Integer number = friendService.countFriendWei(Jpid);
        return number;
    }

    //未同意的加好友数量
    @GetMapping(value = "countFriendNo")
    public Integer countFriendNo(Integer userId){
        Integer number = friendService.countFriendNo(userId);
        return number;
    }
}
